package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.enums.eCrossRankActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.entity.rank.stronghold.CrossActivityUnionRank;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.logic.cross.CrossGeneralActivityUnionRankModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.server.manager.activity.CrossGeneralActivityRankMgr;

import java.util.HashMap;
import java.util.Map;

public class CrossRank extends BaseCrossRank {
    private int childType;
    public CrossRank(int activityId, int childType) {
        super(activityId);
        this.childType = childType;
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {

        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        CrossActivityRankListModel rankListModel = ActivityRankMgr.getCrossActivityRankListModel(activityId);
        if (rankListModel != null) {
            int conditionType = 0;
            if (childType == eCrossRankActivityType.CrossEarnSpeedRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.EarnSpeedRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossIntimacyRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.IntimacyRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossAbilityRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.AbilityRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossQualificationRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.QualificationRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossBanquetPopularityRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.BanquetPopularityRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossChildEarnSpeedRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.ChildEarnSpeedRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossGlamourRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.GlamourRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossClinicScoreRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.ClinicScoreRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossManorOutPutCountRank.getValue()) {
                conditionType = eGamePlayerEventType.ManorOutPutCountRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossBeautyEscortAddExpRank.getValue()) {
                conditionType = eGamePlayerEventType.BeautyEscortAddExpRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossWineShopPleasureRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.WineShopPleasureRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossMonopolyMarketResGrabRank.getValue()) {
                conditionType = eGamePlayerEventType.MonopolyMarketRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossFishPondScoreRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.FishPondRankActivityRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossGrandChildEarnSpeedRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.CrossGrandChildEarnSpeedRiseRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossOnlyEscortAddExpRank.getValue()) {
                conditionType = eGamePlayerEventType.OnlyEscortAddExpRank.getValue();
            } else if (childType == eCrossRankActivityType.CrossDrugStoreTongBiRiseRank.getValue()){
                conditionType = eGamePlayerEventType.DrugStoreTongBiCrossUserRank.getValue();
            }else if (childType == eCrossRankActivityType.CrossWineryAromaRiseRank.getValue()) {
                conditionType = eGamePlayerEventType.WineryAromaRankActivityCrossUserRank.getValue();
            }
            int rank = 0;
            for (CrossUserRank rankData : rankListModel.getRankList()) {
                long userId = rankData.getUserId();
                rank++;
                addUserRankData(msg, conditionType, userId, rank);
            }
        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {

        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        HashMap<Integer, CrossGeneralActivityUnionRankModel> model = CrossGeneralActivityRankMgr.getCrossActivityUnionRankListModel(activityId);
        for (Map.Entry<Integer, CrossGeneralActivityUnionRankModel> entry : model.entrySet()) {
            CrossGeneralActivityUnionRankModel rankListModel = entry.getValue();
            int conditionType = rankListModel.getConditionType();
            int rank = 0;
            for (CrossActivityUnionRank rankData : rankListModel.getRankList()) {
                String unionUid = rankData.getUnionUid();
                rank++;
                addUnionRankData(msg, conditionType, unionUid, rank);
            }
        }
        return msg;
    }
}
